package com.onlinetickets.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MyOpenHelper extends SQLiteOpenHelper {
    public MyOpenHelper(Context context) {
        super(context, "ticket.db", null, 1);
    }

    // 初次使用软件时创建数据库表
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql_user = "create table user(id Integer primary key autoincrement," +
                "username text,password text,realname text,telNumber Integer,email text,idCard Integer)";
        db.execSQL(sql_user);

        String sql_ticket = "create table Ticket(TrainCode text primary key ," +
                "StartStation text,StartTime text,ArriveStation text," +
                "ArriveTime text,UseTime text,TicketNum Integer, TicketPrice real,Date text)";

        db.execSQL(sql_ticket);
        db.execSQL("insert into Ticket values(?,?,?,?,?,?,?,?,?)", new Object[]{"K81",
                "武昌", "01:07", "广州", "13:42", "10小时35分", "100", "150", "2016-6-6"});

        db.execSQL("insert into Ticket values(?,?,?,?,?,?,?,?,?)", new Object[]{"T10",
                "武昌", "08:07", "广州", "16:29", "8小时22分", "100", "170", "2016-6-6"});

        db.execSQL("insert into Ticket values(?,?,?,?,?,?,?,?,?)", new Object[]{"C7",
                "武昌", "08:07", "广州", "10:29", "8小时22分", "100", "170", "2016-6-7"});

        db.execSQL("insert into Ticket values(?,?,?,?,?,?,?,?,?)", new Object[]{"SB",
                "广州", "08:07", "武昌", "9:36", "10小时22分", "100", "170", "2016-6-7"});

        db.execSQL("insert into Ticket values(?,?,?,?,?,?,?,?,?)", new Object[]{"TTC1",
                "广州", "18:07", "北京", "22:07", "4小时0分", "10", "3000", "2016-6-8"});

        String sql_order = "create table tbl_order(id Integer primary key autoincrement," +
                "trainCode text ,startStation text,startTime text,arriveStation text," +
                "arriveTime text,username text,userIdNum Integer, ticketPrice real,date text,status text)";
        db.execSQL(sql_order);
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {

    }

}
